package br.com.viamais.business.bean;

import java.util.List;

import br.com.viamais.business.IUserBO;
import br.com.viamais.dao.UserDAO;
import br.com.viamais.infra.business.bean.BaseBO;
import br.com.viamais.model.User;

/**
 * Business to user bean.
 * 
 * TODO: Logger
 * 
 * @author Eduardo
 */
public class UserBO extends BaseBO<User> implements IUserBO{

	/**
	 * Serial version ID.
	 */
	private static final long serialVersionUID = 8399051550675148420L;
	/**
	 * DAO of user.
	 */
	private UserDAO userDAO;

	/**
	 * Constructor.
	 */
	public UserBO() {
		super();
		userDAO = new UserDAO();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public User getByUserNamePassword(String username, String password) throws Throwable {
		return userDAO.getByUserNamePassword(username, password);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void saveOrUpdate(User user) throws Throwable {
		userDAO.saveOrUpdate(user);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public User getById(Integer id) throws Throwable {
		return userDAO.getById(id);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public User load(Integer id) throws Throwable {
		return userDAO.load(id);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public User getByEmail(String email) throws Throwable {
		return userDAO.getByEmail(email);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<User> getAll() throws Throwable {
		return userDAO.getAll();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void delete(User user) throws Throwable {
		userDAO.delete(user);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<User> getByNameUsername(String name, String username) throws Throwable {
		if(name == null || name.isEmpty()) {
			name = null;
		}
		if(username == null || username.isEmpty()) {
			username = null;
		}
		return userDAO.getByNameUsername(name, username);
	}
}
